package Tools;

import org.exist.xmldb.EXistResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmldb.api.base.Collection;
import org.xmldb.api.base.XMLDBException;
import org.xmldb.api.modules.XMLResource;

/**
 * Created by Oliver Mrazik on 8. 6. 2014.
 * author: Oliver Mrazik
 * version: 2014-06-08
 */
public class DBTools {

    public static final Logger logger = LoggerFactory.getLogger(DBTools.class);

    /**
     * Method close given resource.
     * @param res resource to close
     */
    public static void resourceClose(XMLResource res) {

        // close resource
        if (res != null) {
            try {
                ((EXistResource) res).freeResources();
            } catch (XMLDBException ex) {
                logger.warn("Error freeing resource.");
            }
        }
    }

    /**
     * Method close given collection.
     * @param col collection to close
     */
    public static void collectionClose(Collection col) {

        //close collection
        if (col != null) {
            try {
                col.close();
            } catch (XMLDBException ex) {
                logger.warn("Error freeing collection.");
                //throw new DatabaseException(ex);
            }
        }

    }
}
